import {
  AuthMgtTableItem,
  AuthMgtTableParam,
  AuthPolicyItem,
  DetailItem,
  DetailParam,
} from './model/authorityMgtModel';
import { workOrderHttp } from '/@/utils/http/axios';

enum Api {
  GET_AUTH_MGT_TABLE = '/v1/authorityPolicy/page',
  GET_AUTH_POLICY_LIST = '/v1/authorityPolicy/policyList',
  GET_POLICY_DETAIL = '/v1/authorityPolicy',
}

export const getAuthMgtTable = async (params: AuthMgtTableParam) => {
  const res = await workOrderHttp.get<AuthMgtTableItem>({
    url: Api.GET_AUTH_MGT_TABLE,
    params,
  });
  res.records.map((item) => {
    return (item.isBuiltInStr = item.isBuiltIn ? '内置' : '非内置');
  });
  return res;
};

export const getAuthPolicy = async () => {
  const res = await workOrderHttp.get<AuthPolicyItem>({
    url: Api.GET_AUTH_POLICY_LIST,
  });
  return res;
};

export const getPolicyDetail = async (params: DetailParam) => {
  const res = await workOrderHttp.get<DetailItem>({
    url: Api.GET_POLICY_DETAIL,
    params,
  });
  return res;
};
